<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改系统用户信息')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-user-edit" th:object="${user}">
            <input name="uId" th:field="*{uId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">登陆账户：</label>
                <div class="col-sm-8">
                    <input name="loginName" th:field="*{loginName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">登陆密码：</label>
                <div class="col-sm-8">
                    <input name="loginPawd" th:field="*{loginPawd}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">用户真实姓名：</label>
                <div class="col-sm-8">
                    <input name="trueName" th:field="*{trueName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">用户电话：</label>
                <div class="col-sm-8">
                    <input name="uPhone" th:field="*{uPhone}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">用户状态：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <label class="toggle-switch switch-solid">
                            <input type="checkbox" id="uSstatus" checked>
                            <span></span>
                        </label>
                    </div>
                </div>
            </div>
         
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">过期日期：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="overDate" th:value="${#dates.format(user.overDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/user"
        $("#form-user-add").validate({
            focusCleanup: true
        });
        $("#form-user-edit").validate({
            onkeyup: false,
            rules:{
                loginName:{
                    minlength: 2,
                    maxlength: 20,
                    remote: {
                        url: prefix + "/checkLoginNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "loginName": function() {
                                return $.common.trim($("#loginName").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                password:{
                    minlength: 5,
                    maxlength: 20
                },
                uPhone:{
                    isPhone:true,
                    remote: {
                        url: prefix + "/checkPhoneUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "uPhone": function () {
                                return $.common.trim($("#uPhone").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
            },
            messages: {
                "loginName": {
                    remote: "用户已经存在"
                },
                "uPhone":{
                    remote: "手机号码已经存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            var chrtype = [[${#strings.defaultString(@config.getKey('sys.account.chrtype'), 0)}]];
            var loginPawd = $("#loginPawd").val();
            if ($.validate.form() && checkpwd(chrtype, loginPawd)) {
                var data = $("#form-user-edit").serializeArray();
                var status = $("input[id='uStatus']").is(':checked') == true ? 0 : 1;
                var srId = $.form.selectCheckeds("srId");
                var itId = $.form.selectSelects("itId");
                var trueName = $.form.selectSelects("trueName");
                data.push({"name": "uStatus", "value": status});
                data.push({"name": "srId", "value": srId});
                data.push({"name": "itId", "value": itId});
                data.push({"name": "trueName", "value": trueName});
                console.log("姓名",data)
                $.operate.save(prefix + "/edit", data);
            }
        }
    </script>
</body>
</html>